<?php 
class RegController extends Controller{

	public function __init(){
		
		define('__TEMPLATE__',__ROOT__ .'/Template/jd');
	}
	public function index(){
		if (IS_POST) {
			$data=array();
			$code=strtoupper($_POST['code']);
			if ($code==$_SESSION['code']) {
				$data['username']=$_POST['username'];
				if ($_POST['password']==$_POST['repassword']) {
					$data['password']=$_POST['password'];
					M('user')->add($data);
					$this->success('注册成功！','index/login/index');
				}else{
					$this->error('两次密码输入不一致','index/reg/index');
				}
			}else{
				$this->error('验证码输入错误','index/reg/index');
			}
		}else{
			$this->display('Template/jd/reg.html');
		}
	}
	public function code(){
		$code=new Code();
		$code->show();
	}
	public function checkCode(){
		echo Q('code', '', 'strtoupper') == $_SESSION['code'] ? 1 : 0;
        exit;
	}
}

